package com.zcyr.config;

import com.zcyr.controller.interceptor.AuthControlInterceptor;
import com.zcyr.controller.interceptor.OAuthInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

@Configuration
public class WebMvcConfigurer extends WebMvcConfigurationSupport {

    @Autowired
    private OAuthInterceptor oAuthInterceptor;

    @Autowired
    private AuthControlInterceptor authControlInterceptor;

    @Override
    protected void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(authControlInterceptor)
                .addPathPatterns("/user/**")
                .addPathPatterns("/login/**");

        registry.addInterceptor(oAuthInterceptor)
            .addPathPatterns("/sql/execute")
            .addPathPatterns("/user/**");
        super.addInterceptors(registry);
    }
}
